package com.dji.dao;

import com.dji.model.Mission;
import com.dji.model.Waypoint;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 任务数据访问对象，用于模拟任务数据存储
 */
public class MissionDao {
    private static final Map<String, Mission> missions = new HashMap<>();
    
    /**
     * 获取所有任务列表
     */
    public List<Mission> getAllMissions() {
        return new ArrayList<>(missions.values());
    }
    
    /**
     * 根据ID获取任务
     */
    public Mission getMissionById(String id) {
        return missions.get(id);
    }
    
    /**
     * 根据无人机ID获取任务列表
     */
    public List<Mission> getMissionsByDroneId(String droneId) {
        List<Mission> result = new ArrayList<>();
        for (Mission mission : missions.values()) {
            if (mission.getDroneId().equals(droneId)) {
                result.add(mission);
            }
        }
        return result;
    }
    
    /**
     * 保存或更新任务信息
     */
    public void saveMission(Mission mission) {
        missions.put(mission.getId(), mission);
    }
    
    /**
     * 删除任务
     */
    public void deleteMission(String id) {
        missions.remove(id);
    }
    
    /**
     * 更新任务状态
     */
    public void updateMissionStatus(String id, String status) {
        Mission mission = missions.get(id);
        if (mission != null) {
            mission.setStatus(status);
        }
    }
    
    /**
     * 添加航点到任务
     */
    public void addWaypointToMission(String missionId, Waypoint waypoint) {
        Mission mission = missions.get(missionId);
        if (mission != null) {
            mission.addWaypoint(waypoint);
        }
    }
}